#include <iostream>
#include <stack>
#include <string>

bool is_valid_sequence(const std::string& s) {
    std::stack<char> stack;
    for (char c : s) {
        switch (c) {
        case '(':
        case '[':
        case '{':
        case '<':
            stack.push(c);
            break;
        case ')':
            if (stack.empty() || stack.top() != '(') return false;
            stack.pop();
            break;
        case ']':
            if (stack.empty() || stack.top() != '[') return false;
            stack.pop();
            break;
        case '}':
            if (stack.empty() || stack.top() != '{') return false;
            stack.pop();
            break;
        case '>':
            if (stack.empty() || stack.top() != '<') return false;
            stack.pop();
            break;
        default:
            break;
        }
    }
    return stack.empty();
}

int main() {
    std::string sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> sequence;
    std::cout << (is_valid_sequence(sequence) ? "true" : "false") << std::endl;
    return 0;
}
